package CutLoad.components
{
	import CutLoad.Base;
	import CutLoad.components.container.CScrollV;
	import CutLoad.components.tree.Tree;
	import CutLoad.components.tree.TreeEvent;

	public class CTree extends Base
	{
		private var container:CScrollV;
		private var tree:Tree;
		private var lastWidth:Number=0,lastHeight:Number=0;
		public function CTree(data:XML,w:Number,h:Number,offsetSpeed:Number=0.3,isShowUpDownBtn:Boolean=true,barSpeed:Number=2)
		{
			
			tree=new Tree();
			tree.setWH(w);
			tree.dataProvider=data;
			tree.addEventListener(TreeEvent.CLICK_NODE,clickNode);
			//
			container=new CScrollV(tree,tree.getShowWidth(),h,offsetSpeed,isShowUpDownBtn,barSpeed,true);
			container.show(this);
		}
		private function clickNode(e:TreeEvent):void{
			if(tree.getShowHeight()!=lastHeight||tree.getShowWidth()!=lastWidth){
				container.refresh();
				lastHeight=tree.getShowHeight()
				lastWidth=tree.getShowWidth()
			}
			this.dispatchEvent(new TreeEvent(e.type,e.item,true));
			e.stopPropagation();
		}
		override public function getShowWidth():Number{
			return container.getShowWidth();
		}
		override public function getShowHeight():Number{
			return container.getShowHeight();
		}
	}
}